import { getToken } from "@/utils/auth"
import { Route, Redirect } from "react-router-dom"
const AuthRoute = ({ component: Component, ...rest }) => {
  const token = getToken()
  return (
    <Route
      {...rest}
      render={(props) => {
        // 这里来判断 有无token
        if (token) {
          // 有token直接渲染组件
          return <Component></Component>
        }
        return (
          <Redirect
            to={{
              pathname: "/login",
              state: { from: props.location.pathname }, // 记录访问失败的页面地址
            }}
          ></Redirect>
        )
      }}
    ></Route>
  )
}
// Route =>  path  component    path  render => JSX 渲染
export default AuthRoute

// 访问/a页面 => 没有权限 => /login => /a
